/* =================================================================================
File name:        RMP_CNTL.H  
===================================================================================*/


#ifndef __RAMP_H__
#define __RAMP_H__

typedef struct
{
	F32	   Step;				// Variable: Temp variable
	F32	   Half_Step;			// Variable: Temp variable
	F32    Step_Deceleration;
	F32    Half_Step_Deceleration;
	F32    LowerLimit;			// Parameter: Minimum limit (pu)
	F32    UpperLimit;			// Parameter: Maximum limit (pu)
	F32    TargetValue; 		// Input: Target input (pu)
	F32    CurrentValue;		// Output: Target output (pu)
} RMPCNTL;

/*------------------------------------------------------------------------------
 	RAMP Controller Macro Definition
------------------------------------------------------------------------------*/

STATIC_INLINE void Ramp_Calc( RMPCNTL *p )
{
	p->TargetValue = middle_f32(p->LowerLimit,p->TargetValue,p->UpperLimit);
	p->CurrentValue = middle_f32(p->LowerLimit,p->CurrentValue,p->UpperLimit);

	if(p->CurrentValue + p->Half_Step < p->TargetValue)
	{
		p->CurrentValue = p->CurrentValue + p->Step;
	}
	else if(p->CurrentValue> p->TargetValue + p->Half_Step_Deceleration )
	{
		p->CurrentValue = p->CurrentValue - p->Step_Deceleration;
	}
	else
	{
		p->CurrentValue = p->TargetValue;
	}
	
	p->CurrentValue = middle_f32(p->LowerLimit,p->CurrentValue,p->UpperLimit);
}

#endif // __RMP_CNTL_H__
